# Contributor: Christoph Reiter <reiter.christoph@gmail.com>

_realname=pluggy
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.13.0
pkgrel=1
pkgdesc='Plugin and hook calling mechanisms for python (mingw-w64)'
url='https://github.com/pytest-dev/pluggy'
license=('MIT')
arch=('any')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools-scm"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools-scm"
             "${MINGW_PACKAGE_PREFIX}-python2-importlib-metadata")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python2-pytest-runner" 
              "${MINGW_PACKAGE_PREFIX}-python3-pytest-runner")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/pytest-dev/pluggy/archive/${pkgver}.tar.gz")
sha512sums=('cc946bf3e003e0c6fd04d113682560c6e2c84ffa790a6177f43cd5754d25248bae33af6aa77d86c938cea31bc386af9ada88d61499071a6216da1fd94bc11773')

prepare() {
  for pver in {2,3}; do
    rm -rf python${pver}-build-${CARCH} | true
    cp -r "${_realname}-${pkgver}" "python${pver}-build-${CARCH}"
  done
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  for pver in {2,3}; do
    msg "Python ${pver} build for ${CARCH}"
    cd "${srcdir}/python${pver}-build-${CARCH}"
    MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
      ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done
}

check() {
  for pver in {2,3}; do
    msg "Python ${pver} test for ${CARCH}"
    cd "${srcdir}/python${pver}-build-${CARCH}"
    MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
      ${MINGW_PREFIX}/bin/python${pver} setup.py pytest
  done
}

package_python3-pluggy() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3")

  cd ${srcdir}/python3-build-${CARCH}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} -O1 --root="${pkgdir}" --skip-build

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE"
}

package_python2-pluggy() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2"
           "${MINGW_PACKAGE_PREFIX}-python2-importlib-metadata")

  cd ${srcdir}/python2-build-${CARCH}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} -O1 --root="${pkgdir}" --skip-build

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE"
}

package_mingw-w64-i686-python2-pluggy() {
  package_python2-pluggy
}

package_mingw-w64-i686-python3-pluggy() {
  package_python3-pluggy
}

package_mingw-w64-x86_64-python2-pluggy() {
  package_python2-pluggy
}

package_mingw-w64-x86_64-python3-pluggy() {
  package_python3-pluggy
}
